#41-字符串格式化
# print('%s is %s years old' % ('bob', 20))
# print('%s is %d years old' % ('bob', 20))       #d是整数
# print('%s is %d years old' % ('bob', 20.5))     #只取整体。
# print('%s is %f years old' % ('bob', 23.5))     #%f是浮点型，默认六位小数
# print('%s is %5.2f years old' % ('bob', 23.5))  #5.2f是宽度为五，2为小数
# print('%s is %4.3f years old' % ('bob', 12345.5))
# print('97 is %c' % 97)                             #97的是序号a
# print("11 is %#o" % 11)                          ##o表示8进制
# print('%10s%5s' % ('name','age'))                #10个宽度，5右对齐
# print('%10s%5s' %  ('bob','20'))
# print('%10s%5s' %  ('alice', 20))
# print("%-10s%-5s" % ('tom',23))                  #- 负号
# print('%10d ' % 123)
# print('%010d' % 123)                               #十位整数，右对齐，之前以0补齐
# "{} is {} years old".format('bob', 25)
# "{1} is {0} years old".format(25, 'bob')
# "{:<10}{:<8}".format('name', 'age')
#42-shutil模块常用方法
# import shutil
# with open('/etc/passwd','rb') as sfobj:
#     with open('/tmp/mima.txt', 'wb') as dfobj:
#         shutil.copyfileobj(sfobj,dfobj)
# shutil.copyfile('/etc/passwd', '/tmp/mima.txt')
# shutil.copy('etc/passwd', '/tmp/mima.txt')     #cp
# shutil.copy2('/etc/passwd', '/tmp/mima.txt')     #cp -p
# shutil.move('/etc/passwd', '/tmp/mima.txt')      #mv
# shutil.copytree('/etc/passwd', '/tmp/mima.txt')     #cp -r
# shutil.rmtree('/etc/passwd', '/tmp/mima.txt')       #rm -rf
# shutil.copymode('/etc/passwd', '/tmp/mima.txt')     ## 将mima2.txt的元数据设置成与/etc/shadow一样
# shutil.copystat()# 元数据使用stat /etc/shadow查看
# shutil.chown('/tmp/mima2.txt', user= 'zhangsan',group='zhangsan')
#43-练习：生成文本文件
# import os
# def get_fname():
#     while True:
#         fname = input('filename:')
#         if  not os.path.exists(fname):
#             break
#         print('%s 文件已存在' % fname )
#     return fname
#
# def get_content():
#     content = []
#     print('输入数据，输入end结束')
#     while True:
#         line = input('')
#         if line == 'end':
#             break
#         line.append(line)
#     return content
# def wfile(fname,content):
#     with open(fname,'w') as fobj:
#         fobj.writelines(content)
#
#
#
#
# if __name__ == '__main__':
#     fname = get_fname()
#     content = get_fname()
#     content = ['%s\n' % line for line in content]
#     wfile(fname,content)
#44-列表方法
# alist = [1, 2, 3, 'bob', 'alice']
# alist[0] = 10
# alist[1:3] = [20, 30]
# alist[2:2] = [22, 24, 26, 28]
# alist.append(100)
# alist.remove(24)  # 删除第一个24
# alist.index('bob')  # 返回下标
# blist = alist.copy()  # 相当于blist = alist[:]
# alist.insert(1, 15)  # 向下标为1的位置插入数字15
# alist.pop()  # 默认弹出最后一项
# alist.pop(2) # 弹出下标为2的项目
# alist.pop(alist.index('bob'))
# alist.sort()
# alist.reverse()
# alist.count(20)  # 统计20在列表中出现的次数
# alist.clear()  # 清空
# alist.append('new')
# alist.extend('new')
# alist.extend(['hello', 'world', 'hehe'])
#已敲完并理解
#45-检查合法标识符
# import sys
# import keyword
# import string
#
# first_chs = string.ascii_letters + '_'
# all_chs = first_chs + string.digits
#
# def check_id(idt):
#     if keyword.iskeyword(idt):
#         return "%s is keyword" % idt
#
#     if idt[0] not in first_chs:
#         return "1st invalid"
#
#     for ind, ch in enumerate(idt[1:]):
#         if ch not in all_chs:
#             return "char in postion #%s invalid" % (ind + 2)
#
#     return "%s is valid" % idt
#
#
# if __name__ == '__main__':
#     print(check_id(sys.argv[1]))  # python3 checkid.py abc@123



















